﻿<%@ Page Language="C#" AutoEventWireup="true" Inherits="Syrinx.Gui.AspNet.Nitobi2.NitobiBasePage" 
	 MasterPageFile="~/App_ThemeMasters/NoStyle/popUpTwoColumnLayout.Master" %>
<%@ Register Assembly="Swaf.Gui.AspNet2" Namespace="Swaf.Gui.AspNet2" TagPrefix="swf" %>
<%@ Register Assembly="ScsAspNet" Namespace="Syrinx.Gui.AspNet.Nitobi2" TagPrefix="snc" %><%@ Register Assembly="NitobiControls" Namespace="Nitobi" TagPrefix="ntb" %>

<asp:Content ContentPlaceHolderID="headSection" runat="server">
	<script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAAQBzXgHvh7En6ix21Lkj_PRTZTwA8LlS11r-EQgx_FIxZEnDlfxS0NfLmQvJF9hfasBVTJsPqSZ4tQw"></script></head>
	<script type="text/javascript">	google.load("maps", "2");</script>
	<script type="text/javascript" src="http://www.google.com/jsapi?key=ABCDEFG"></script>
</asp:Content>

<asp:Content ContentPlaceHolderID="leftContent" ID="content2" runat="server">
	<div class="AddressArea">
	<input type="text" id="location" style="width:50%" /> <button type="button" onclick="geoCode()">Find</button> <button type="button" onclick="save()">Save Map Location</button>
	</div>
	<script>
		var googleKey = 'ABQIAAAA-ByhZxU9vTeEy6zbCreE1RQo0j6YqQNz_Gg3VYBYZ5fZ7NrGFRSXV6sh7PJEUgdOHJZwKHQIib5FMQ';
		var gmap = null;
	google.setOnLoadCallback(initialize);

	$(window).resize(function() {
		$("#map").height($(window).height() - ($(".AddressArea").height() + 20 ));
	});
	function initialize() {
		gmap = new google.maps.Map2(document.getElementById("map"));
		gmap.addControl(new GLargeMapControl()); //Adds zoom/pan support
		gmap.addControl(new GMapTypeControl());

		var addr = window.dialogArguments;
		if (addr != null) {
			document.getElementById("location").value = getAddrAtt("street1") + "," + getAddrAtt("city") + "," + getAddrAtt("stateProvince");
			if (getAddrAtt("longitude") != "" && getAddrAtt("latitude") != "")
				gmap.setCenter(new google.maps.LatLng(new Number(getAddrAtt("latitude")), new Number(getAddrAtt("longitude"))), 13);
			else			
				geoCode(function(pt) {
					if (pt == null) {
						document.getElementById("location").value = getAddrAtt("city") + "," + getAddrAtt("stateProvince");
						geoCode();
					}
				});
		}
		else
			gmap.setCenter(new google.maps.LatLng(37.4419, -122.1419), 13);
	}
	function getAddrAtt(name) {
		var addr = window.dialogArguments;
		if (addr.getAttribute(name))
			return addr.getAttribute(name);
		if (addr.getAttribute("location." + name))
			return addr.getAttribute("location." + name);
		return "";
	}
	function setAddrAtt(name, val) {
		var addr = window.dialogArguments;
		if (addr.hasAttribute(name)) {
			return addr.setAttribute(name, val);
		}
		if (addr.hasAttribute("location." + name)) {
			return addr.setAttribute("location." + name, val);
		}
	}
	function save() {
		var addr = window.dialogArguments;
		if (addr != null) {
			var pt = gmap.getCenter();
			setAddrAtt("longitude", pt.lng());
			setAddrAtt("latitude", pt.lat());
			window.returnValue = addr;
			window.close();
		}	
	}
	function geoCode(doWhenDone) {
		var gc = new GClientGeocoder();
		gc.getLatLng(document.getElementById("location").value, function(pt) {
			if (pt != null) {
				gmap.setCenter(pt);
			}
			if(doWhenDone != null)
				doWhenDone(pt);
		});
	}
	</script>
	<div id="map" style="width:100%;height:400px">
	</div>
</asp:Content>